<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 用户输入内容 -->
        <input type="text" @keyup.enter="addfinished()" v-model="finishedtext">

        <!-- 未完成 -->
        <h1>未完成事件</h1>
        <div class="not-finished">
            <div v-for="(item,index) in notFinishedArr" :key="item.id"> 
                <input type="checkbox" v-model="item.isChecked" @change="isfinished(item,index)">
                <span>{{item.thing}}</span>
                    {{item.id}}
                <button @click="notFremove(index)">删除</button>
            </div>
        </div>

        <!-- 已经完成 -->
        <h1>已经完成事件</h1>
        <div class="finished">
            <div  v-for="(item,index) in finishedArr" :key="item.id">
                <input type="checkbox" v-model="item.isChecked" @change="isNotFinished(item,index)">
                <span>{{item.thing}}</span>
                {{item.id}}
                <button @click="Fremove(index)">删除</button>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        let vm = new Vue({
            el: "#app",
           
            data: {
                arrId:4,
                finishedtext:'',
                // 未完成的事情
                notFinishedArr: [{
                    id: 1,
                    thing: "敲代码",
                    isChecked: false
                },
                 {
                    id:2,
                    thing: "整理笔记",
                    isChecked: false
                }],
                //  已完成的事情
                finishedArr: [{
                    id: 3,
                    thing: "脑袋放空, 进入提前放假模式",
                    isChecked: true
                }]
            },
            methods: {
                addfinished(){   
                    this.notFinishedArr.push({
                    id: this.arrId++,
                    thing: this.finishedtext,
                    isChecked: false
                    });
                    this.finishedtext=''
                },
                notFremove(index){
                    this.notFinishedArr.splice(index,1);
                },
                Fremove(index){
                    this.finishedArr.splice(index,1);
                },
                isfinished(item,index){
                    this.notFinishedArr.splice(index,1);
                    this.finishedArr.push(item);
                },
                isNotFinished(item,index){
                    this.notFinishedArr.push(item);
                    this.finishedArr.splice(index,1);
                }


            },
            watch:{
                // notFinishedArr:{
                //     deep:true,
                //     handler(val){
                //         let arr={}
                //         this.notFinishedArr.forEach((item,index)=>{
                //           item.isChecked==true&&(arr=item,this.notFinishedArr.splice(index,1));
                           
                //         })
                //         this.finishedArr.push(arr);
                //     }
                // }
            }
        })
    </script>
</body>

</html>